<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<label class="layui-form-label">活动状态:<span style="color:red">*</span></label>
								<div class="layui-input-block seckill_status">

								</div>
							</div>
							<div class="layui-form-item" style="display: none;">
								<label class="layui-form-label">选择店铺：</label>
								<div class="layui-input-inline">
									<input type="text" name="shopid" class="layui-input" id="shopid" autocomplete="off" placeholder="选择店铺：">
								</div> 
								<div class="layui-form-mid layui-word-aux">
									<a href="Javascript:;" onclick="searchdata('shopid')">选择</a>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">选择店铺：</label>
								<div class="layui-input-block">
									<textarea type="text" name="shopname" class="layui-textarea" id="shopname" autocomplete="off" placeholder="选择店铺：" readonly=""></textarea>
								</div> 
								<div class="layui-form-mid layui-word-aux layui-input-block">
									<a href="Javascript:;" onclick="searchdata('shopid')">选择</a>
								</div>
							</div>
							
							
							<div class="layui-form-item">
								<label class="layui-form-label">开始日期：</label>
								<div class="layui-input-inline">
									<input type="text" name="dates" class="layui-input" id="dates" autocomplete="off" placeholder="开始日期：">
								</div>
								<label class="layui-form-label">开始时间：</label>
								<div class="layui-input-inline">
									<input type="text" name="times" class="layui-input" id="times" autocomplete="off" placeholder="开始时间：">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">结束时间：</label>
								<div class="layui-input-inline">
									<input type="text" name="endtime" class="layui-input" id="endtime" autocomplete="off" placeholder="结束时间：">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">备注</label>
								<div class="layui-input-block">
									<textarea type="text" id="notes" name="notes" autocomplete="off" placeholder="备注：" class="layui-textarea" /></textarea>
								</div>
							</div>

						</div>
					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id')
			}
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'upload', 'colorpicker'], function() {
				var $ = layui.$,
					admin = layui.admin,
					upload = layui.upload,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					layedit = layui.layedit,
					colorpicker = layui.colorpicker;
				form = layui.form;

				if(_data.id) {
					initdata();
				}

				//日期时间选择器
				laydate.render({
					elem: '#dates',
					type: 'date'
				});
				//日期时间选择器
				laydate.render({
					elem: '#times',
					type: 'time'
				});
				//日期时间选择器
				laydate.render({
					elem: '#endtime',
					type: 'datetime'
				});
				//表单赋值
				colorpicker.render({
					elem: '#test-form',
					done: function(color) {
						$('#color').val(color);
					}
				});
				seckill_status_show('radio')

				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					layer.confirm('确定要提交数据？', function() {
						loading();
						if(_data.id) {
							submitdata(server.seckill_edit);
						} else {
							delete _data.id
							submitdata(server.seckill_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}

				function initdata() {
					$.get(server.seckill_detail, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								var data = res.seckill
								
								form.val("test_detail", data.data);
								
								if(res.seckill.data.shopname){
									var data2 = res.seckill.data.shopname[0]
									console.log(data2)
									form.val("test_detail", data2);
								}
								
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				window.searchdata = function(type) {
					switch(type) {
						case 'shopid':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_shop.html',
								end: function() {},
								success: function() {}
							});
							break;
					}
				}
			});
		</script>
	</body>

</html>